<?php
/**
 * 验证码校验，对应接口为/common/validate_mobile_token
 * User: devforma
 * Date: 14/12/16
 * Time: 11:44
 */

class ValidateMobileToken implements iController {
    /**
     * api请求处理主函数
     * 
     * @param array $queryArgs $_REQUEST变量
     * @return array api返回结果，含response_code
     */
    public function output($queryArgs)
    {
        if (!isset($queryArgs['mobile_num']) || !validatePhone($queryArgs['mobile_num'])
        || !($memValue = cacheGet('phone:'.$queryArgs['mobile_num']))) {
            return genOutput(1000); //参数错误
        }

        if (!isset($queryArgs['mobile_token']) || !validateCode($queryArgs['mobile_token'])
        || $memValue['code'] != $queryArgs['mobile_token']) {
            return genOutput(1000); //参数错误
        }

        //更新cache，标记该手机号已经验证OK
        $memValue['validated'] = true;
        cacheSet('phone:'.$queryArgs['mobile_num'], $memValue, 10*60);

        return genOutput(1);    //成功
    }
}